﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Markup;
using Creventive.Wpf.ShellFactory.Modules;

namespace MultiViewWithLogin.Infrastructure.Shell
{
    /// <summary>
    ///   Adds additional properties to the master ViewSources.
    /// </summary>
    [ContentProperty("ViewSources")]
    public class Widgets
    {
        #region Static Fields/Constants

        public static readonly DependencyProperty ExtensionProperty = DependencyProperty.RegisterAttached("Extension", typeof(Widgets), typeof(Widgets), new UIPropertyMetadata(null));

        #endregion

        private ObservableCollection<WidgetViewSource> viewSources;

        /// <summary>
        ///   Initializes a new instance of the <see cref = "Widgets" /> class.
        /// </summary>
        public Widgets()
        {
            this.viewSources = new ObservableCollection<WidgetViewSource>();
        }

        /// <summary>
        ///   Gets the master view references collection.
        /// </summary>
        /// <value>The view references.</value>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ObservableCollection<WidgetViewSource> ViewSources
        {
            get { return this.viewSources; }
        }

        /// <summary>
        ///   Gets an extension for the given module, if available.
        /// </summary>
        /// <param name = "module">The module.</param>
        /// <returns></returns>
        public static Widgets GetExtension(ApplicationModule module)
        {
            return (Widgets)module.GetValue(ExtensionProperty);
        }

        /// <summary>
        ///   Sets an extension on the given module, if available. Must be called before the shell is loaded.
        /// </summary>
        /// <param name = "module">The module.</param>
        /// <param name = "value">The value.</param>
        public static void SetExtension(ApplicationModule module, Widgets value)
        {
            module.SetValue(ExtensionProperty, value);
        }
    }
}